package com.aos.erp.gov.ex.task.mq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Bean
    public Queue toGovNewStudent() {
        return new Queue(QueueConstants.toGovNewStudent);
    }

    /**
     * 交换机
     *
     * @return
     */
    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange(QueueConstants.gov_direct_exchange);
    }

    @Bean
    public Queue toGovStudentSubmitted() {
        return new Queue(QueueConstants.toGovStudentSubmitted);
    }

    @Bean
    public Queue toGovStudentSuccess() {
        return new Queue(QueueConstants.toGovStudentSuccess);
    }

    @Bean
    public Queue toGovStudentFailed() {
        return new Queue(QueueConstants.toGovStudentFailed);
    }


    @Bean
    public Binding bindingDirectExchangeSubmitted(Queue toGovStudentSubmitted, DirectExchange directExchange) {
        return BindingBuilder.bind(toGovStudentSubmitted).to(directExchange).with(QueueConstants.gov_direct_exchange_key_submitted);
    }

    @Bean
    public Binding bindingDirectExchangeSuccess(Queue toGovStudentSuccess, DirectExchange directExchange) {
        return BindingBuilder.bind(toGovStudentSuccess).to(directExchange).with(QueueConstants.gov_direct_exchange_key_success);
    }

    @Bean
    public Binding bindingDirectExchangeFailed(Queue toGovStudentFailed, DirectExchange directExchange) {
        return BindingBuilder.bind(toGovStudentFailed).to(directExchange).with(QueueConstants.gov_direct_exchange_key_failed);
    }


    @Bean
    public Jackson2JsonMessageConverter jsonMessageConverter() {
        Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
        return converter;
    }


}
